<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
         <h2><if condition="ACTION_NAME eq 'add'">新建<else/>编辑</if>用户</h2>
    </div>
    <form action="{:U()}" method="post" class="form-horizontal">
        <div class="form-item">
            <label class="item-label">用户名<span class="check-tips">（用户名会作为默认的昵称）</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="username" value="{$edit.nickname}">
                <input type="hidden" class="text input-large" name="uid" value="{$edit.uid}">
            </div>
        </div>
        <if condition="ACTION_NAME eq 'add'">
        <div class="form-item">
            <label class="item-label">密码<span class="check-tips">（用户密码不能少于6位）</span></label>
            <div class="controls">
                <input type="password" class="text input-large" name="password" value="">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">确认密码</label>
            <div class="controls">
                <input type="password" class="text input-large" name="repassword" value="">
            </div>
        </div>
        <else/>
        </if>
        <div class="form-item">
            <label class="item-label">客服等级<span class="check-tips"></span>
            </label>
            <div class="controls">
                <select class="field" name="jb">
                      <volist name="authgroup" id="vo">     
                            <option value="{$vo.id|default=null}" <eq name="vo.id" value="$edit.jb_id"> selected</eq>>{$vo.title|default=null}</option>
                      </volist>
                </select>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">微信openID<span class="check-tips"></span></label>
            <div class="controls">
                       
                      <select class="field1" name="openid">  
                            <option value="{$edit.openid|default=null}">{$weixin.nickname|default=null}</option>
                      </select>
            </div>
        </div>
        <if condition="ACTION_NAME eq 'add'">
        <div class="form-item">
            <label class="item-label">邮箱<span class="check-tips">（用户邮箱，用于找回密码等安全操作）</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="email" value="">
            </div>
        </div>
        <else/>
        </if>
        <div class="form-item">
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">
       
        $(document).ready(function(){
            $(".field").change(function(){
                $.post("{:U('getOpenId')}",{"id":$(this).val()},function(data){
                       // var data = eval(data);
                        if(data.status == 0){
                           $(".field1").find("option").remove();
                        }else{
                        if(data.length >= 2 ){
                           $(".field1").find("option").remove();
                        for(var i = 0;i<data.length;i++){
                           $(".field1").append("<option value=\"" + data[i].id + "\">" + data[i].title +"</option>");
                        }     
                        }else{
                           $(".field1").find("option").remove();
                           $(".field1").append("<option value=\"" + data.id + "\">" + data["title"] +"</option>");
                        }          
                        }
                            });
             
            });
        });
        //导航高亮
        highlight_subnav('{:U('Kefu/index')}');
    </script>
</block>
